//
//  YellowPagesTypeViewController.m
//  ExcellentHome
//
//  Created by liangxinqiang on 14-11-22.
//  Copyright (c) 2014年 陈区. All rights reserved.
//

#import "ActivityListCell.h"
#import "SEGOtherCreateActivityDetailViewController.h"
#import "SEGActivityTypeViewController.h"

@interface SEGActivityTypeViewController ()

@end

@implementation SEGActivityTypeViewController
@synthesize typeAry;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)loadView
{
    [super loadView];
    
    m_tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds) - kNavigationBarAndStatusBarHeight) style:UITableViewStylePlain];
    m_tableView.delegate = self;
    m_tableView.dataSource = self;
    m_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    m_tableView.backgroundColor = [UIColor clearColor];
    [m_tableView registerClass:[ActivityListCell class] forCellReuseIdentifier:kActivityListCellIdentifier];
    
    [self.view addSubview:m_tableView];
}


- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self showCustomNavigationBackButton];
    
    self.title = self.naTitle;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark -
#pragma mark Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    
    return [self.typeAry count];
    
    
}
- (CGFloat)tableView:(UITableView *) tableView heightForRowAtIndexPath:(NSIndexPath *) indexPath{
    return 80;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    NSInteger row = indexPath.row;
    
    ActivityListCell *cell = [ActivityListCell cellWithTableView:tableView];
    cell.dataSource = [self.typeAry objectAtIndex:indexPath.row];
    
    //每个section最后一个活动 线和屏幕等宽
    if (row==[self.typeAry count]-1) {
        cell.isLastRow = YES;
    }else {
        cell.isLastRow = NO;
    }
    return cell;
}


#pragma mark -
#pragma mark Table view delegate

- (void)deselectRowDelay
{
    [m_tableView deselectRowAtIndexPath:[m_tableView indexPathForSelectedRow] animated:YES];
    
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    [self performSelector:@selector(deselectRowDelay) withObject:nil afterDelay:0.3];
    ActivityModel *entity = [self.typeAry objectAtIndex:indexPath.row];

    SEGOtherCreateActivityDetailViewController *detailCtl = [[SEGOtherCreateActivityDetailViewController alloc] init];
    detailCtl.hidesBottomBarWhenPushed = YES;
//    [detailCtl addActivityData:entity];
    NSDictionary *data = @{@"data":entity};
    [detailCtl addActivityData:[data valueForKey:@"data"]];
    [self.navigationController pushViewController:detailCtl animated:YES];

    
}

@end
